var app = getApp();
var helper =require('../../utils/helper.js')


Page({

  /**
   * 页面的初始数据
   */
  data: {
    bookDatas: [],
    musicDatas: [],
    movieDatas: [],
    result: '',
    myhost: app.globalData.remoteDomainMy,
    totalPrice:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  onShow: function() {
    //获取本地存储数据
    let openid = wx.getStorageSync('openid');
    let storageDatas = wx.getStorageSync(openid);
    if (storageDatas) {
      //图书
      var bookArr = storageDatas.book;

      // 音乐
      var musicArr = storageDatas.music;

      // 电影
      var movieArr = storageDatas.movie;

      //统计总价
      let totalPrice = helper.countPrice(storageDatas);

      //渲染到模板
      this.setData({
        result: '',
        bookDatas: bookArr,
        musicDatas: musicArr,
        movieDatas: movieArr,
        totalPrice: totalPrice
      })
    } else {
      this.setData({
        result: '暂无数据！'
      })
    }
  },


  /**
   * 数量+1
   */
  add: function(e) {
    helper.addsub(e, app.globalData.openid, this,'add')
  },

  /**
   * 数量-1
   */
  sub: function (e) {
    helper.addsub(e, app.globalData.openid, this, 'sub')
  },

  /**
   * 删除
   */
  del:function(e){
    console.log('删除');
    var that = this;

    wx.showModal({
      title: '提示',
      content: '确定删除吗？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          helper.addsub(e, app.globalData.openid, that, 'del')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
  },

  gopay:function(){
    wx.navigateTo({
      url: '../pay/pay',
    })
  }
})